import json
from utils import read_sql
import pandas as pd


with open("miss_time.json", "r") as fp:
    data = json.load(fp)
df = read_sql(f"select * from k_line2 where symbol='BTC' and datasource = 'binance' "
              f"and frequency = '1h' order by datetime",
              db_name="all_history_ohlcvm_coinmarketcap")
df["date"] = df["datetime"].dt.date
miss_time_list = data["miss_time"]
miss_df = pd.DataFrame(miss_time_list, columns=["time"])
miss_df["datetime"] = pd.to_datetime(miss_df["time"])
miss_df["date"] = miss_df["datetime"].dt.date
for date, group in miss_df.groupby("date"):
    miss_str = ",".join(group["time"].tolist())
    print("miss_time:", miss_str)
    tmp_df = df[df["date"] == date]
    columns = ["datetime","close", "vol", "amount"]
    print(tmp_df[columns])
